﻿/*----------------------------------------------------
 * Author : Tharinduni Udugamasuriya
 * FinCon dll for Handeling DB 
 * Connection : Handeling DB connection - inner
 ---------------------------------------------------*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;

namespace DSPL.DataAccess
{
    public class Connection:IDisposable 
    {
        #region Construtor

        public Connection()
        { }

        #endregion

        #region IDisposable Members

        public void Dispose()
        {
            GC.SuppressFinalize(this);
        }

        #endregion

        public SqlConnection getSqlConnection(string DataSource, string Username, string Password, bool isDbAvail, string Database = null)
        {
            SqlConnectionStringBuilder finConstr = new SqlConnectionStringBuilder();
            finConstr.DataSource = DataSource;
            finConstr.UserID = Username;
            finConstr.Password = Password;
            finConstr.IntegratedSecurity = true;
            if (isDbAvail)
            {
                finConstr.InitialCatalog = Database;
            }
            SqlConnection con = new SqlConnection(finConstr.ToString());
            return con;
        }

        public SqlConnection getSqlConnection(string ConnectionString)
        {
            SqlConnection con = new SqlConnection(ConnectionString);
            return con;
        }
    }
}
